#include <bits/stdc++.h>

using namespace std;
struct TreeNode
{
    int val;
    TreeNode *left = nullptr;
    TreeNode *right = nullptr;
    TreeNode(int x)
    {
        val = x;
    }
};
class Solution
{
public:
    vector<string> ret;
    void dfs(string path, TreeNode *root)
    {
        if (root->left == nullptr && root->right == nullptr)
        {
            path += to_string(root->val);
            ret.push_back(path);
            return;
        }
        else
        {
            path += to_string(root->val);
            path += "->";
            if (root->left)
                dfs(path, root->left);
            if (root->right)
                dfs(path, root->right);
        }
    }
    vector<string> binaryTreePaths(TreeNode *root)
    {
        dfs("", root);
        return ret;
    }
};